package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.account.AbstractAccount;
import com.acme.bankapp.domain.account.CheckingAccount;
import com.acme.bankapp.domain.account.SavingsAccount;
import com.acme.bankapp.domain.bank.*;
import com.acme.bankapp.domain.client.Client;
import com.acme.bankapp.domain.client.Gender;


public class BankApplication {
	
	public static void addClient(Bank bank, Client client){
		
		try {
			BankService.addClient(bank, client);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		
	}
	
	public static void withdraw(Client client, double sum){
		try {
			client.getAccount().withdraw(sum);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		
	}

	public static void modifyBank(Bank bank){
		for (Client client : bank.getClients()) {
			withdraw(client, 200);
		}	
			
	}
	
	public static void addClientsTest(Bank bank){
		
		Client client1 = new Client("Ivanov", Gender.MALE, (new CheckingAccount(50, 100)));
		Client client2 = new Client("Petrova", Gender.FEMALE, (new CheckingAccount(30)));
		Client client3 = new Client("Ivanov", Gender.MALE, (new CheckingAccount(50, 100)));
		Client client4 =  new Client("Sidorov", Gender.MALE, (new SavingsAccount(100)));
		
		addClient(bank, client1);
		addClient(bank, client2);
		addClient(bank, client3);
		addClient(bank, client4);
		
	}
	
	public static void TestEqualsAndHashCode(){
		
		AbstractAccount testsaveac1 = new SavingsAccount(100);
		AbstractAccount testsaveac2 = new SavingsAccount(100);
		
		if(testsaveac1.equals(testsaveac2)){
			System.out.println(testsaveac1 + " equals " + testsaveac2);
			System.out.println(testsaveac1.hashCode());
			System.out.println(testsaveac2.hashCode());
		} else {
			System.out.println(testsaveac1 + " not equals " + testsaveac2);
		}			
				
		
		Client testclient1 = new Client("John", Gender.MALE, testsaveac1);
		Client testclient2 = new Client("Mira", Gender.FEMALE, testsaveac2);
		
		if(testclient1.equals(testclient2)){
			System.out.println(testclient1 + " equals " + testclient2);
		
		} else {
			System.out.println(testclient1 + " not equals " + testclient2);
		}	
		System.out.println("hashCode");
		System.out.println("testclient1 - " + testclient1.hashCode());
		System.out.println("testclient2 - " + testclient2.hashCode());
		
		if(testclient1.equals(testclient1)){
			System.out.println(testclient1 + " equals " + testclient1);
		}
		
		
	}
	
	public static void main(String[] args) {
		
		Bank bank = BankService.createNewBank();
		
		addClientsTest(bank);
						
		BankService.printBalance(bank);
		
		modifyBank(bank);
		
		BankService.printBalance(bank);
		
		TestEqualsAndHashCode();

	}

}
